package com.bauer.base.thread;

public class InterrupteDemo {

    /**
     * 阻塞线程的方法  sleep join wait  会抛出中断异常
     * @param args
     */
    public static void main(String[] args) {
        Thread  thread1=  new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("thread1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });


        Thread  thread2=  new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("thread2");
                while (!Thread.currentThread().isInterrupted()){
                    System.out.println("thread22");
                }
            }
        });

        thread1.start();
        thread2.start();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        thread1.interrupt();
        thread2.interrupt();
        while (thread1.isInterrupted()){

        }
        System.out.println("thread1 isInterrupted: " + thread1.isInterrupted());
        System.out.println("thread2 isInterrupted: " + thread2.isInterrupted());
    }
}
